package com.nxy.test.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by snailnan on 2017/2/22.
 */
public class NioSocketServer {
    public static final ExecutorService pool = Executors.newCachedThreadPool();

    public static void main(String[] args) throws IOException {

        ServerSocketChannel service = ServerSocketChannel.open();
        service.configureBlocking(false);
        service.socket().bind(new InetSocketAddress(6666));
        while (true){
            SocketChannel sc = service.accept();
            if (sc != null){
                pool.submit(new NioServerThread(sc));
            }
        }
    }

}
